package com.sneaker.shower;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.github.binarywang.wxpay.bean.request.WxPayDownloadBillRequest;
import com.github.binarywang.wxpay.bean.result.WxPayBillInfo;
import com.github.binarywang.wxpay.bean.result.WxPayBillResult;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.sneaker.shower.common.AES;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.util.Base64Utils;

import java.time.LocalDate;
import java.util.List;

public class OrderQuery {


    private static WxPayService wxPayService;

    private static WxMaService wxMaService;

    private static WxMpService wxMpService;

    private static void init() {
        initPayService();
        initMaService();
        initMpService();
    }

    private static void initPayService() {
        String appId = "wx9533925657696e59";
        String mchId = "1538160231";
        String mchKey = "kaFnJqSV9yjB8w0RyL82XolhSsGe286X";
        String subAppId = "";
        String subMchId = "";
        String keyPath = "D://sneaker-cert//WXCertUtil//cert//1538160231_20190831_cert//apiclient_cert.p12";

        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(appId);
        payConfig.setMchId(mchId);
        payConfig.setMchKey(mchKey);
        payConfig.setSubAppId(subAppId);
        payConfig.setSubMchId(subMchId);
        payConfig.setKeyPath(keyPath);
        // 可以指定是否使用沙箱环境
        payConfig.setUseSandboxEnv(false);
        wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig);
    }

    private static void initMaService() {
        String appId = "wx9533925657696e59";
        String appSecret = "0ee077bf23cdf90c051c5ab842b6dfb6";
        String token = "SneakerShower";
        String AESKey = "kaFMenJqSV9yc1jB8w0RsUyL9j82XolhSsGe2sw8X6X";
        String msgDataFormat = "JSON";
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();

        wxMaConfig.setAppid(appId);
        wxMaConfig.setSecret(appSecret);
        wxMaConfig.setToken(token);
        wxMaConfig.setAesKey(AESKey);
        wxMaConfig.setMsgDataFormat(msgDataFormat);
        wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(wxMaConfig);
    }

    private static void initMpService() {
        String appId = "wx1d9ef13f602e5bea";
        String appSecret = "1a21a10f11a32c279ac4155323919009";
        String token = "SneakerShower";
        String AESKey = "5DWKghkly4y9VmfmhNJTK420OpePkVsRxSk4XiydCUR";
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(appId);
        wxMpDefaultConfig.setSecret(appSecret);
        wxMpDefaultConfig.setToken(token);
        wxMpDefaultConfig.setAesKey(AESKey);

        wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpDefaultConfig);
    }

    public static void main(String[] args) throws WxPayException, WxErrorException {
        init();
//        FileService fileService = new FileService();
//        LocalDate date = LocalDate.of(2019, 9, 28);
//        LocalDate end = LocalDate.of(2019, 10, 31);
        System.out.println(wxPayService.queryOrder(null, "1208279454238617601"));


        // 小程序收款码
//        String orgGuid = "1217730611008114690";
//        try {
//            System.out.println(Base64Utils.encodeToString(AES.encrypt(orgGuid).getBytes()));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

}
